{extend name="../../base/view/common/base" /}

<!-- 主体 -->
{block name="body"}
<div class="p-page">
	<table class="layui-hide" id="test" lay-filter="test"></table>
</div>

<script type="text/html" id="status">
	<i class="layui-icon {{#  if(d.status == 'normal'){ }}green layui-icon-ok{{#  } else { }}yellow layui-icon-close{{#  } }}"></i>
</script>
<script type="text/html" id="is_use">
	{{#  if(d.is_use == 0){ }}全员{{#  } else { }}指定{{#  } }}
</script>
<script type="text/html" id="is_notice">
	{{#  if(d.is_notice == 0){ }}全员{{#  } else { }}指定{{#  } }}
</script>
<script type="text/html" id="is_admin">
	{{#  if(d.is_admin == 0){ }}全员{{#  } else { }}指定{{#  } }}
</script>
<script type="text/html" id="category_name">
	{{ d.category.name }}
</script>
<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-sm" lay-event="add">+ 添加应用</button>
	</div>
</script>
<script type="text/html" id="barDemo">
<div class="layui-btn-group">
	<button class="layui-btn layui-btn-xs layui-btn-normal" lay-event="use">使用权限</button>
	<button class="layui-btn layui-btn-xs layui-btn-normal" lay-event="notice">通知权限</button>
	<button class="layui-btn layui-btn-xs layui-btn-normal" lay-event="admin">管理权限</button>
	<button class="layui-btn layui-btn-xs" lay-event="edit">编辑</button>
	<button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button>
</div>
</script>

{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool'];
	function gouguInit() {
		var table = layui.table, tool = layui.tool;
		layui.pageTable = table.render({
			elem: '#test',
			title: '岗位列表',
			toolbar: '#toolbarDemo',
			defaultToolbar: false,
			url: "/xapply/myapp/index", //数据接口				
			page: false, //开启分页
			cols: [
				[
					{
						field: 'id',
						title: 'ID号',
						align: 'center',
						width: 80
					}, {
						field: 'category_name',
						toolbar: '#category_name',
						title: '所在分组',
						align: 'center',
					}, {
						field: 'name',
						title: '应用名称',
						align: 'center',
					}, {
						field: 'app_name',
						title: '标识',
						align: 'center',
					}, {
						field: 'weigh',
						title: '权重',
                        align: 'center',
						width: 120
					}, {
						field: 'status',
						toolbar: '#status',
						title: '状态',
						align: 'center',
					}, {
						field: 'is_use',
						title: '使用权限',
						toolbar: '#is_use',
						align: 'center',
					}, {
						field: 'is_notice',
						title: '通知权限',
						toolbar: '#is_notice',
						align: 'center',
					}, {
						field: 'is_admin',
						title: '管理权限',
						toolbar: '#is_admin',
						align: 'center',
					}, {
						field: 'url',
						title: '应用地址',
						align: 'center',
					}, {
						field: 'right',
						title: '操作',
						toolbar: '#barDemo',
						width: 280,
						align: 'center'
					}
				]
			]
		});

		//表头工具栏事件
		table.on('toolbar(test)', function(obj){
			if (obj.event === 'add') {
				tool.side("/xapply/myapp/add");
				return;
			}
		});
		//监听行工具事件
		table.on('tool(test)', function (obj) {
			var data = obj.data;
			if(obj.event === 'use'){
				tool.side('/xapply/myapp/perm?type=0&id='+data.id);
				return;
			}
			if(obj.event === 'notice'){
				tool.side('/xapply/myapp/perm?type=1&id='+data.id);
				return;
			}
			if(obj.event === 'admin'){
				tool.side('/xapply/myapp/perm?type=2&id='+data.id);
				return;
			}
			if(obj.event === 'edit'){
				tool.side('/xapply/myapp/add?id='+data.id);
				return;
			}
			if (obj.event === 'del') {
				layer.confirm('您确定要删除应用吗？', {
					icon: 3,
					title: '提示'
				}, function (index) {
					let callback = function (e) {
						layer.msg(e.msg);
						if (e.code == 0) {
							obj.del();
						}
					}
					tool.delete("/xapply/myapp/delete", { id: obj.data.id }, callback);
					layer.close(index);
				});
			}
		});
	}
</script>
{/block}
<!-- /脚本 -->